package com.scrcu.idea.ormns.model.po;

import com.google.common.base.CaseFormat;

import java.util.HashSet;
import java.util.Set;

public class Web extends Base {

    private Business business;
    private String projectName;

    public Web(String projectName, String moduleName, String author, String comment, String name , Business business) {
        super(moduleName, comment, name, author);
        this.business = business;
        this.projectName = projectName;
    }

    public Business getBusiness() {
        return business;
    }

    public String getProjectName() {
        return projectName;
    }

    public String getSimpleUrl() {
        String tableNameStr = business.getDao().getModel().getTableName();
        return tableNameStr.lastIndexOf("_") == -1 ? tableNameStr : tableNameStr.replaceAll("_","/");
    }

    public String getSimpleService() {
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, business.getDao().getModel().getTableName())+ "Service";
    }

    public String getLowerSimpleService() {
        return getSimpleService().substring(0, 1).toLowerCase() + getSimpleService().substring(1);
    }

    @Override
    public Set<String> getImports() {
        Set<String> imports = new HashSet<>();
        imports.add(business.getDao().getModel().getPackagePath() + "." + business.getDao().getModel().getSimpleName());
        imports.add(business.getPackagePath() + "." + business.getSimpleName());
        return imports;
    }

}
